package com.basic.modules.sys.controller;

import java.util.Arrays;

import cn.hutool.core.util.ObjectUtil;
import com.basic.common.exception.RRException;
import com.basic.common.utils.ParamsModel;
import com.basic.common.validator.ValidatorUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.basic.modules.sys.entity.SysEmailConfigEntity;
import com.basic.modules.sys.service.SysEmailConfigService;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.R;

import javax.mail.MessagingException;


/**
 * 系统用户
 *
 * @author maoheng
 * @email 15738859597@163.com
 * @date 2024-11-22 15:06:22
 */
@RestController
@RequestMapping("sys/emailConfig")
public class SysEmailConfigController {

    @Autowired
    private SysEmailConfigService sysEmailConfigService;

    /**
     * 列表-分页
     */
    @PostMapping("/page")
    public R list(@RequestBody ParamsModel<SysEmailConfigEntity> params) throws MessagingException {
        PageUtils page = sysEmailConfigService.queryPage(params);
        return R.ok(page);
    }

    /**
     * 信息
     */
    @PostMapping("/info")
    public R info(@RequestBody SysEmailConfigEntity params){
        if (ObjectUtil.isEmpty(params) || ObjectUtil.isEmpty(params.getEmailConfigId())) {
            throw new RRException("参数缺失");
        }
        return R.ok(sysEmailConfigService.getById(params.getEmailConfigId()));
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SysEmailConfigEntity sysEmailConfig){
        ValidatorUtils.validateEntity(sysEmailConfig);
		sysEmailConfigService.save(sysEmailConfig);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody SysEmailConfigEntity sysEmailConfig){
        ValidatorUtils.validateEntity(sysEmailConfig);
		sysEmailConfigService.updateById(sysEmailConfig);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] emailConfigIds){
		sysEmailConfigService.removeByIds(Arrays.asList(emailConfigIds));
        return R.ok();
    }

}
